package ar.edu.unicen.pladema.ui.panel.options;

import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;

import ar.edu.unicen.pladema.main.SWTUtils;
import ar.edu.unicen.pladema.ui.mywidgets.FileSelector;
import ar.edu.unicen.pladema.ui.mywidgets.PointXYZPanel;
import ar.edu.unicen.pladema.ui.mywidgets.RangeCoor;
import ar.edu.unicen.pladema.vc1.model.GraphicAttributes;
import ar.edu.unicen.pladema.vc1.practico.PanelOption;
import ar.edu.unicen.pladema.vc1.practico3.P3Enunciado1Drawer;

public class POP3E1 extends PanelOption {
	private FileSelector fileSelector;
	private RangeCoor rangeX;
	private RangeCoor rangeY;
	private RangeCoor rangeZ;
	private PointXYZPanel pointLight;
	private P3Enunciado1Drawer p3ed;
	
	public POP3E1(Composite parent, IPaintIt pi, GraphicAttributes ga,
			P3Enunciado1Drawer p3ed) {
		super(parent, pi, ga);
		this.p3ed = p3ed;
		this.fileSelector.setGraphicAttributes(this.graphicAttributes);
	}

	@Override
	protected void createWidgetsImpl() {
		fileSelector = new FileSelector(this);
		rangeX = new RangeCoor(this,"X");
		rangeY = new RangeCoor(this,"Y");
		rangeZ = new RangeCoor(this,"Z");
		pointLight = new PointXYZPanel(this,"POINT_LIGHT");
	}

	@Override
	protected FormData layoutWidgets(FormData fd) {
		fileSelector.setLayoutData(fd);
		pointLight.setLayoutData(SWTUtils.createBelowFormData(fileSelector, 5));
		rangeX.setLayoutData(SWTUtils.createBelowFormData(pointLight, 5));
		rangeY.setLayoutData(SWTUtils.createBelowFormData(rangeX, 5));
		rangeZ.setLayoutData(SWTUtils.createBelowFormData(rangeY, 5));
		return SWTUtils.createBelowFormData(rangeZ, 5);
	}

	@Override
	protected void loadGraphicData() {
		rangeX.setValues(
				graphicAttributes.getDouble("RCXmin"), 
				graphicAttributes.getDouble("RCXmax"));
		
		rangeY.setValues(
				graphicAttributes.getDouble("RCYmin"), 
				graphicAttributes.getDouble("RCYmax"));
		
		rangeZ.setValues(
				graphicAttributes.getDouble("RCZmin"), 
				graphicAttributes.getDouble("RCZmax"));
		pointLight.setValues(
				graphicAttributes.getDouble("XLight"), 
				graphicAttributes.getDouble("YLight"), 
				graphicAttributes.getDouble("ZLight"));
		fileSelector.setFile(graphicAttributes.get(GraphicAttributes.FILE_NAME));
		p3ed.openFile(graphicAttributes.get(GraphicAttributes.FILE_NAME));
	}

	@Override
	protected void saveGraphicData() {
	}

}
